import axios from "axios"

const service = axios.create({
  baseURL: 'http://localhost/',
  timeout: 10 * 3000
});

//请求拦截器
service.interceptors.request.use(config => {
  const jwt = window.localStorage.getItem('ten-seek-jwt');
  if(jwt) {
    config.headers["Authorization"] = "bearer " + jwt;
  }
  return config;
}, error => {
  Promise.reject(error);
})

//响应拦截器
service.interceptors.response.use(
  (response) => {
    return response.data;
  },
  error => {
    return Promise.reject(new Error(error.reponse.data));
  }
)

export default service;